#ifndef MOTO_H
#define MOTO_H

#include <QString>
#include <QWidget>
#include "../TableWidgetForm.h"

struct MotoConnectStr
{
    QString name;
    QString type;

    // 获取结构体成员名的字符串
    QString toFieldNames() const {
        return QString("name,type");
    }

    // 获取结构体成员名的字符串
    QStringList toFieldTypes() const {
        QStringList _list;
        _list << typeid(name).name();
        _list << typeid(type).name();
        return _list;
    }
};

struct MotoMotoStruct
{
    int id;
    QString name;
    int currentlocation;
    int speed;
    int maxspeed;
    int board_id;
    int phyid;
    int enable;

    // 获取结构体成员名的字符串
    QString toFieldNames() const {
        return QString("name,currentlocation,speed,maxspeed,board_id,phyid,enable");
    }

    // 获取结构体成员名的字符串
    QStringList toFieldTypes() const {
        QStringList _list;
        _list << typeid(name).name();
        _list << typeid(currentlocation).name();
        _list << typeid(speed).name();
        _list << typeid(maxspeed).name();
        _list << typeid(board_id).name();
        _list << typeid(phyid).name();
        _list << typeid(enable).name();
        return _list;
    }
};

class Moto
{
public:
    Moto();

    //初始化UI
    static void InitUI(const QString& fileName, QList<QPair<QWidget *, QString>>& widgets, QMap<int, QList<TableWidgetForm*>>& m_pTableWidgetFormMap);

    //保存
    static bool SaveUI(const QString& fileName, const QMap<int, QList<TableWidgetForm*>>& m_pTableWidgetFormMap);

    //解析350
    static void Analysis(const QString& path, MotoConnectStr& str, QList<MotoMotoStruct>& motos);

    //保存350
    static bool SaveXml(const QString& path, const MotoConnectStr& str, const QList<MotoMotoStruct>& motos);
};

#endif // MOTO_H
